package com.at.appmodel;

import java.util.HashSet;
import java.util.Set;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Build;


@SuppressLint("NewApi")
public class APPPreferences {
     private static final String APP_SHARED_PREFS = "com.at.app"; //  Name of the file -.xml
     private SharedPreferences appSharedPrefs;
     private Editor prefsEditor;

     public APPPreferences(Context context)
     {
         this.appSharedPrefs = context.getSharedPreferences(APP_SHARED_PREFS, Activity.MODE_PRIVATE);
         this.prefsEditor = appSharedPrefs.edit();
     }
     
     
     public String getAlertTimeFrom() {
         return appSharedPrefs.getString("AlertTimeFrom", new String());
     }

     public void setAlertTimeFrom(String datefrom) {
         prefsEditor.putString("AlertTimeFrom", datefrom);
         prefsEditor.commit();
     }
     //---------------------------------------------------------------------------------------------
     
     
     /*
      * 
      */     
     public String getAlertTimeTo() {
         return appSharedPrefs.getString("AlertTimeto", new String());
     }

     public void setAlertTimeTo(String dateto) {
         prefsEditor.putString("AlertTimeto", dateto);
         prefsEditor.commit();
         
     }     
     //---------------------------------------------------------------------------------------------

     
     /*
      * 
      */     
     public int getAlertTimeInterval() {
         return appSharedPrefs.getInt("AlertTimeInterval", 0);
     }

     public void setAlertTimeInterval(int interval) {
         prefsEditor.putInt("AlertTimeInterval", interval);
         prefsEditor.commit();
         
     }
     //---------------------------------------------------------------------------------------------
     
     
     /*
      * 
      */     
     public Set<String> getSelectedWeekdaysAlert() {
    	 
    	 if(Build.VERSION.SDK_INT >=  Build.VERSION_CODES.HONEYCOMB){
    		 return appSharedPrefs.getStringSet("Weekdays",  new HashSet<String>());
    	 }
    	 
    	 Set<String> Weekdays	= new HashSet<String>();
    	 
    	 Weekdays.add(appSharedPrefs.getString("So", new String()));
    	 Weekdays.add(appSharedPrefs.getString("Mo", new String()));
    	 Weekdays.add(appSharedPrefs.getString("Di", new String()));
    	 Weekdays.add(appSharedPrefs.getString("Mi", new String()));
    	 Weekdays.add(appSharedPrefs.getString("Do", new String()));
    	 Weekdays.add(appSharedPrefs.getString("Fr", new String()));
    	 Weekdays.add(appSharedPrefs.getString("Sa", new String()));
    	 
    	 return Weekdays;
     }     
     
     public void setSelectedWeekdaysAlert(Set<String> weekdays) {
    	 
    	 if(Build.VERSION.SDK_INT >=  Build.VERSION_CODES.HONEYCOMB){
    		 prefsEditor.putStringSet("Weekdays" , weekdays);
    		 prefsEditor.commit();
    	 }else{
    		 

		    for (String day : weekdays) {
		    	prefsEditor.putString(day , day);
		    }    		 
    		 
    		 prefsEditor.commit();   		 
    		 
    	 }
         
     }
     //---------------------------------------------------------------------------------------------
     
     
     /*
      * 
      */
     public boolean isAlertActive() {
         return appSharedPrefs.getBoolean("AlertActive", false);
     }     
     
     public void setAlertActive(boolean alertActive) {
         prefsEditor.putBoolean("AlertActive" , alertActive);
         prefsEditor.commit();
     }
     //---------------------------------------------------------------------------------------------
     
     /*
      * 
      */     
     public String getVibrationAlert() {
         return appSharedPrefs.getString("VibrationAlert", new String());
     }     
     
     public void setVibrationAlert(String vibration) {
         prefsEditor.putString("VibrationAlert" , vibration);
         prefsEditor.commit();
         
     }
     //---------------------------------------------------------------------------------------------
     
     public boolean isApplicationsFirstRun(){
    	 return appSharedPrefs.getBoolean("FirstRun", false);
     }
     
     public void setApplicationsFirstRun(boolean firstRun){
    	 prefsEditor.putBoolean("FirstRun", firstRun);
    	 prefsEditor.commit();
     }
     
     public void setupAtFirstRun(){
         prefsEditor.putString("VibrationAlert" , "S.O.S");
         prefsEditor.commit();
     }
     
}
